package org.eden.web.pojo;

import lombok.Data;

@Data
public class Response {
    private Object data;
    private int code;
    private String msg;

    public Response(States state) {
        this.msg = state.getMsg();
        this.code = state.getCode();
    }

    public Response(int code, Object data) {
        this.code = code;
        this.data = data;
    }

    public Response(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Response success(Object data) {
        return new Response(States.REQUEST_SUCCESS.getCode(), States.REQUEST_SUCCESS.getMsg(), data);
    }

    public static Response failed(String msg) {
        return new Response(States.REQUEST_FAILED.getCode(), msg, null);
    }

    public static Response busy() {
        return new Response(States.REQUEST_FAILED.getCode(), "服务器繁忙", null);
    }

}
